# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

pkgbase=libuv
pkgname=("${pkgbase}" "${pkgbase}-devel")
pkgver=1.33.1
pkgrel=1
pkgdesc="Multi-platform support library with a focus on asynchronous I/O"
arch=('i686' 'x86_64')
url="https://github.com/libuv/libuv"
license=('custom')
makedepends=('gcc')
depends=('gcc-libs')
source=("https://github.com/libuv/libuv/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('0200aae2d38c26f537658955479cbc54fb69d5d8cbbccf3016cea319b2c46b1f311ca7a8fc289f14532acbbf2905cf96b17353b8b92bf09802424c372701d1d5')

prepare() {
  cd "${srcdir}"/${pkgname}-${pkgver}
  ./autogen.sh
}

build() {
  cd "${srcdir}"/${pkgbase}-${pkgver}
  ./configure --host=${CHOST} \
              --build=${CHOST} \
              --prefix=/usr

  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}"/${pkgbase}-${pkgver}
  # a few of these tests are known to fail.
  make check || true
}

package_libuv() {
  groups=('libraries')

  cd "${srcdir}"/${pkgbase}-${pkgver}
  install -Dm644 LICENSE \
    "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
  install -Dm644 AUTHORS \
    "${pkgdir}"/usr/share/doc/${pkgname}/AUTHORS
  install -Dm644 README.md \
    "${pkgdir}"/usr/share/doc/${pkgname}/README.md
  install -Dm644 ChangeLog \
    "${pkgdir}"/usr/share/doc/${pkgname}/ChangeLog
 
  cd "${srcdir}/dest"
  mkdir -p ${pkgdir}/usr/bin
  cp -f usr/bin/*.dll ${pkgdir}/usr/bin
}

package_libuv-devel() {
  groups=('development')
  options=('staticlibs')
  depends=(${pkgbase}=${pkgver})
  pkgdesc="libuv headers and libraries"

  cd "${srcdir}/dest"
  mkdir -p ${pkgdir}/usr/lib
  mkdir -p ${pkgdir}/usr/include

  cp -rf usr/lib/* ${pkgdir}/usr/lib
  cp -rf usr/include/* ${pkgdir}/usr/include
  #This is required for cmake.  
  cp "${srcdir}"/${pkgbase}-${pkgver}/include/uv/posix.h ${pkgdir}/usr/include/uv
}
